﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic.PowerPacks;
using System.Windows.Forms;
using System.Drawing;

namespace LittleBoxes
{
   /// <summary>
   /// Ignore
   /// </summary>
    public class MultiLine : Shape
    {
        public int StartX { get; set; }
        public int StartY { get; set; }
        public int EndX { get; set; }
        public int EndY { get; set; }

        protected override AccessibleObject CreateAccessibilityInstance()
        {
            throw new NotImplementedException();
        }

        public override void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds)
        {
            //int horzCtr = GetHorizontalCenter();
            //if (IsLRTB() || IsRLBT())
            //{
            //    for (int j = StartX; j <= horzCtr; j++)
            //    {
            //        bitmap.SetPixel(j, StartY, Color.Black);
            //    }

            //    for (int i = StartY; i <= EndY; i++)
            //    {
            //        bitmap.SetPixel(horzCtr, i, Color.Black);
            //    }

            //    for (int j = horzCtr; j <= EndX; j++)
            //    {
            //        bitmap.SetPixel(j, EndY, Color.Black);
            //    }

            //}
            //else
            //{
            //    for (int j = StartX; j <= horzCtr; j++)
            //    {
            //        bitmap.SetPixel(j, EndY, Color.Black);
            //    }

            //    for (int i = StartY; i <= EndY; i++)
            //    {
            //        bitmap.SetPixel(horzCtr, i, Color.Black);
            //    }

            //    for (int j = horzCtr; j <= EndX; j++)
            //    {
            //        bitmap.SetPixel(j, StartY, Color.Black);
            //    }
            //}
        }

        public override bool HitTest(int x, int y)
        {
            int horzCtr = GetHorizontalCenter();
            if (IsLRTB() || IsRLBT())
            {
                if (y == StartY && (x >= StartX && x <= horzCtr))
                    return true;
                else if (x == horzCtr)
                    return true;
                else if (y == EndY && (x >= horzCtr && x <= EndX))
                    return true;
                else
                    return false;
            }
            else
            {
                if (y == EndY && (x >= StartX && x <= horzCtr))
                    return true;
                else if (x == horzCtr)
                    return true;
                else if (y == EndY && (x >= horzCtr && x <= EndX))
                    return true;
                else
                    return false;
            }

            return false;
        }

        public override void Scale(SizeF factor)
        {
            

        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.Parent.CreateGraphics();
            g.DrawLine(Pens.Black, new Point(StartX, StartY), new Point(EndX, EndY));
        }

        private int GetHorizontalCenter()
        {
            int halfDistance = (EndX - StartX) / 2;
            return StartX + halfDistance;
        }

        private bool IsLRTB()
        {
            return (StartX < EndX) && (StartY < EndY);
        }

        private bool IsLRBT()
        {
            return (StartX < EndX) && (StartY > EndY);
        }

        private bool IsRLTB()
        {
            return (StartX > EndX) && (StartY < EndY);
        }

        private bool IsRLBT()
        {
            return (StartX > EndX) && (StartY > EndY);
        }

        public int Height
        {
            get
            {
                int h = EndY - StartY;
                if (h < 0) h = -h;
                return h;
            }
        }

        public int Width
        {
            get
            {
                int w = EndX - StartX;
                if (w < 0) w = -w;
                return w;
            }
        }
    }
    
}
